cc.Class({
    extends: cc.Component,

    properties: {
        fireworks: cc.Prefab,
        sfx: cc.AudioClip,
    },
    
    start() {
        // 定义节点对象池
        this.yanhuaPool = new cc.NodePool();
        var count = 200;
        for (var i = 0; i < count; i++) {
            var yanhuaObj = cc.instantiate(this.fireworks);
            this.yanhuaPool.put(yanhuaObj);
        }
        this.schedule(this.createYanhua, 1, 100, 1);
    },
    createYanhua() {
        cc.log("对象池数量：", this.yanhuaPool.size());
        if (this.yanhuaPool.size() > 0) {
            var yanhuaObj = this.yanhuaPool.get();
        }
        else {
            var yanhuaObj = cc.instantiate(this.fireworks);
        }
        yanhuaObj.parent = this.node;
        yanhuaObj.x = -480 + 960 * Math.random();
        yanhuaObj.y = -320 + 640 * Math.random();
        yanhuaObj.getComponent(cc.ParticleSystem).resetSystem();
        this.scheduleOnce(function () {
            yanhuaObj.getComponent(cc.ParticleSystem).stopSystem();
            this.yanhuaPool.put(yanhuaObj);
        }, 4)
    },


    // update (dt) {},
});
